package com.xqit.ydzhkt.payment.controller;

import com.xqit.ydzhkt.api.PaymentApi;
import com.xqit.ydzhkt.common.response.HttpResult;
import com.xqit.ydzhkt.dto.PaymentDto;
import com.xqit.ydzhkt.entity.Payment;
import com.xqit.ydzhkt.payment.service.PaymentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Janus on 2020/6/1
 * 缴费接口
 */
@RestController
@CrossOrigin
@RequestMapping("/payment")
public class PaymentController implements PaymentApi {

    @Autowired
    private PaymentService paymentService;

    //需要缴费的项目
    @PostMapping(value = "/paymentProject", produces = "application/json;charset=utf-8")
    public HttpResult paymentProject(@RequestParam("xh") String xh){

        //参数判空
        if (xh == null || "".equals(xh) || "undefined".equals(xh)){
            return HttpResult.success("学号不能为空");
        }
        //根据学号查询该生需要缴费项目
        List<PaymentDto> payments = paymentService.getPaymentProject(xh);
        return HttpResult.success(payments);
    }

    //微信支付
    @PostMapping(value = "/wxPay", produces = "application/json;charset=utf-8")
    public HttpResult wxPay(@RequestBody Payment payment){
        return HttpResult.success("微信支付成功");
    }

    //缴费记录
    @PostMapping(value = "/paymentRecord", produces = "application/json;charset=utf-8")
    public HttpResult paymentRecord(@RequestParam("xh") String xh){
        //参数判空

        if (StringUtils.isEmpty(xh) || "undefined".equals(xh)){
            return HttpResult.success("学号不能为空");
        }
        //根据学号查询该生已经缴费项目
        List<Payment> paymentRecord = paymentService.getPaymentRecord(xh);
        return HttpResult.success(paymentRecord);
    }
}
